package cn.ilikes.tools.hbase.jpa.query.iquerys;

import java.util.HashMap;
import java.util.Map;
import javax.persistence.Parameter;

import cn.ilikes.tools.hbase.jpa.query.sql.element.KuTable;

public abstract class JPAQuery extends JPAQueryImpl implements IQuery {

	protected Map<Parameter<?>, Object> parameters = new HashMap<Parameter<?>, Object>();

	protected KuTable kuTable;

	protected SqlType sqlType;

	protected String sql;

	public JPAQuery(String sql) {

		this.sql = sql;
	}

	public void setKuTable(KuTable kuTable) {
		this.kuTable = kuTable;
	}

	public SqlType getSqlType() {
		return sqlType;
	}

	public void setSqlType(SqlType sqlType) {
		this.sqlType = sqlType;
	}

	protected KuTable getKuTable() {
		return kuTable;
	}

	@Override
	public String getQuerySql() {
		return sql;
	}

	@Override
	public boolean isDelete() {
		return sqlType.equals(SqlType.delete);
	}

	@Override
	public boolean isSelect() {
		return sqlType.equals(SqlType.select);
	}

	@Override
	public boolean isUpdate() {
		return sqlType.equals(SqlType.update);
	}

	@Override
	public <T> void setParameter(Parameter<T> parameter, Object value) {
		parameters.put(parameter, value);
	}

	@Override
	public void init() {
		kuTable.initVariable(parameters);
	}

	public abstract Object queryResult();

}
